# -*- coding=utf-8 -*-
# 维修手尺 spider
#

import scrapy
import field.repairitems
class RepairSpider(scrapy.Spider):

    name = "repairspider"

    def __init__(self, name=None, **kwargs):
        super(RepairSpider, self).__init__(name, **kwargs)

    def start_requests(self):
        url="http://qczl.ycqpmall.com/";

        yield  scrapy.Request(url=url,callback=self.parse)

    def parse(self, response):
        se = response.xpath('//ul[@class="mui-table-view"]/li').extract()
        for text  in se:
            # gitem= item.xpath('[contains(@class,"mui-table-view-divider")]/text');
            # gitem2 = item.xpath('[contains(@class,"mui-table-view-cell")]/text');
            # if(gitem!=None):
            #     map["group"]=gitem;
            # if(gitem2!=None):
            #     map["item"] = gitem2;
            stext=scrapy.Selector(text=text)
            print  "stext"
            print  stext
            map = field.repairitems.RepairItem()

            if("data-group" in text):
                map["group"]=stext.xpath("//li/text()").extract()

            if("data-value" in text):
                map["itemtypelink"] = stext.xpath("//li//a/@href").extract()
                map["itemtype"] = stext.xpath("//li//a/text()").extract()
            yield  map
        # se = response.xpath('//ul[@class="mui-table-view"]/li[contains(@class,"mui-table-view-divider")]/text()').extract()
        # for item in se:
        #     yield  item;


